(function(){
try{document.body.removeChild(document.getElementById('cheatsheetArea'));}catch(e){}
var lng = ['ja','en'];
var keys = ["c","/","p","n","t","d","x","w","m","a","q","[Esc]"
,"[Enter]","[Tab]","[Ctrl] + [Enter]"];

var messageObj = {
	"c":
		{"ja":"予定を作成"
		,"en":"Create Event"}
	,"/":
		{"ja":"検索"
		,"en":"Search"}
	,"p":
		{"ja":"前の期間"
		,"en":"Previous date range"}
	,"n":
		{"ja":"次の期間"
		,"en":"Next date range"}
	,"t":
		{"ja":"[今日] へ戻る"
		,"en":"Jump to 'Today'"}
	,"d":
		{"ja":"[日] ビュー"
		,"en":"'Day' view"}
	,"x":
		{"ja":"カスタム ビュー"
		,"en":"Customized view"}
	,"w":
		{"ja":"[週] ビュー"
		,"en":"'Week' view"}
	,"m":
		{"ja":"[月] ビュー"
		,"en":"'Month' view"}
	,"a":
		{"ja":"[予定リスト] ビュー"
		,"en":"'Agenda' view"}
	,"q":
		{"ja":"クイック追加"
		,"en":"Quick Add"}
	,"[Esc]":
		{"ja":"カレンダーに戻る"
		,"en":"Back to calendar"}
	,"[Enter]":
		{"ja":"展開"
		,"en":"Expand"}
	,"[Tab]":
		{"ja":"次のフィールド"
		,"en":"Next field"}
	,"[Ctrl] + [Enter]":
		{"ja":"保存"
		,"en":"Save"}
};

var scripts = document.getElementsByTagName('script');
var lng = 'en';
for(var i = 0,len=scripts.length;i<len;i++){
	if(scripts[i].src.indexOf('cs_google_calendar.js') > 0){
		try{
			lng = scripts[i].src.split('?')[1].split('&')[0].split('=')[1];
		}catch(e){}
	}
}

var cheattxt = '<p style="margin:0px;width:100%;background-color:#EEEEEE">[<a id="cheatsheettoggle" href="javascript:void(0);">-</a>] <B id="cs_title">Cheat Sheet</B><a  id="cs_close_btn" href="javascript:void(0);" onclick="document.body.removeChild(document.getElementById(\'cheatsheetArea\'));" style="position:absolute;right:3px">[close]</a><p>'
+'<div id="cheatsheetbody" style="padding:0px;margin:0px;display:block;">'
+'</div>';

var d = document.createElement('div');
d.id='cheatsheetArea'
d.style.position = 'absolute';
d.style.padding = '5px'
d.style.top = '330px';
d.style.left = '2px';
d.style.width = '12em';
d.style.backgroundColor = '#FFFFFF';
d.style.border = '1px solid #999999';
d.style.fontSize = '10pt';
d.style.zIndex = '100000';
d.style.textAlign = 'left';
try{d.style.filter = 'alpha(opacity=90)';}catch(e){}
try{d.style.MozOpacity = '.90';}catch(e){}
try{d.style.opacity = '.90';}catch(e){}

d.innerHTML = cheattxt;
document.body.appendChild(d);
for(var i = 0,len = keys.length;i<len;i++){
	var key = keys[i];
	var appender = document.getElementById('cheatsheetbody');
	var div = document.createElement('div');
	div.innerHTML = '<label style="margin-right:10px;font-weight:bold;">' + key + '</label>' + ':<label style="color:#666666">' + messageObj[key][lng] + '</label>';
	div.style.borderTop = '1px solid #AAAAAA';
	appender.appendChild(div);
}

var a = document.getElementById('cheatsheettoggle');
a.onclick = function(){
	var b = document.getElementById('cheatsheetbody');
	var c = document.getElementById('cheatsheetArea');
	var e = document.getElementById('cs_title');
	var f = document.getElementById('cs_close_btn');
	if(b.style.display == 'none'){
		b.style.display = 'block';
		e.style.display = 'inline';
		f.style.display = 'inline';
		a.innerHTML = '-';
		c.style.width = '12em';
		c.style.height = null;
	}else{
		b.style.display = 'none';
		e.style.display = 'none';
		f.style.display = 'none';
		c.style.width = '15px';
		c.style.height = '13px';
		a.innerHTML = '+';
	}
}
})();
